import request from './request';
import { elMessage, getTimeStamp } from '../utils//util';
import { elMessageType } from '../model/enum';

//创造二维码key的接口
export const createKey = async () => {
  try {
    return request.get(`/login/qr/key?timestamp=${getTimeStamp()}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//产生base64地址的接口
export const createQrCode = async (key: string) => {
  try {
    return request.get(
      `/login/qr/create?key=${key}&qrimg=true&timestamp=${getTimeStamp()}`
    );
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//监测登陆状态的接口
export const checkStatus = async (key: string) => {
  try {
    return request.get(
      `/login/qr/check?key=${key}&timestamp=${getTimeStamp()}`
    );
  } catch (error: any) {
    elMessage(elMessageType.ERROR, '网络错误');
  }
};

//获取用户的账号信息
export const getUserID = async () => {
  try {
    return request.get(`/user/account`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取用户具体信息
export const getUserInfo = async (uid: string) => {
  try {
    return request.get(`/user/detail?uid=${uid}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//退出登陆
export const loginOut = async () => {
  try {
    return request.get(`/logout`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取轮播图片
export const getBanner = async () => {
  try {
    return request.get('/banner?type=0');
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌单信息
export const getPlayerList = async () => {
  try {
    return request.get('/top/playlist');
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取获取推荐的歌曲
export const getDeafultSong = async (limit: number) => {
  try {
    return request.get(`/record/recent/song?limit=${limit}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取音乐的url
export const getMusicUrl = async (id: string) => {
  try {
    return request.get(`/song/url?id=${id}&br=320000`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取mv
export const getMv = async (limit: number, area: string) => {
  try {
    return request.get(`/mv/all?limit=${limit}&area=${area}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌单详情
export const getPlayListDetail = async (id: string) => {
  try {
    return request.get(`/playlist/detail?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌单的所有歌曲
export const getPlayListSong = async (id: string) => {
  try {
    return request.get(`/playlist/track/all?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//判断歌曲是否可用
export const getMuiscAccess = async (id: string) => {
  try {
    return request.get(`/check/music?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取热门搜索列表
export const getHotSearch = async () => {
  try {
    return request.get(`/search/hot/detail`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//根据关键词搜索歌曲
export const searchMusic = async (
  type: number,
  limit: number,
  keywords: string
) => {
  try {
    return request.get(
      `/search?keywords=${keywords}&type=${type}&limit=${limit}`
    );
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取Mv数据
export const getMvDetail = async (id: string) => {
  try {
    return request.get(`/mv/detail?mvid=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取mv的地址
export const getMvUrl = async (id: string) => {
  try {
    return request.get(`/mv/url?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取相关mv
export const getSimiMv = async (id: string) => {
  try {
    return request.get(`/simi/mv?mvid=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取曲风列表
export const getStyleList = async () => {
  try {
    return request.get(`/style/list`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取曲风详情
export const getStylePlayList = async (id: string) => {
  try {
    return request.get(
      `/style/playlist?tagId=${id}&size=${Math.floor(Math.random() * 11 + 13)}`
    );
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌手榜
export const getArtistList = async (type: number) => {
  try {
    return request.get(`/toplist/artist?type=${type}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌手信息
export const getArtistInfo = async (id: string) => {
  try {
    return request.get(`/artists?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌手mv

export const getArtistMv = async (id: string) => {
  try {
    return request.get(`/artist/mv?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌手描述
export const getArtistDesc = async (id: string) => {
  try {
    return request.get(`/artist/desc?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌手专辑
export const getArtistAlbum = async (id: string) => {
  try {
    return request.get(`/artist/album?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取用户最近播放记录
export const getUserRencent = async (uid: string) => {
  try {
    return request.get(`/user/record?uid=${uid}&type=1`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取用户最近观看的视频
export const getUserRecentVideo = async () => {
  try {
    return request.get(`/playlist/video/recent`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取用户喜欢音乐的列表

export const getUserLikes = async (uid: string) => {
  try {
    return request.get(`/likelist?uid=${uid}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取音乐详情
export const getMusicDetail = async (id: string) => {
  try {
    return request.get(`/song/detail?ids=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取专辑详情
export const getAlbumDetail = async (id: string) => {
  try {
    return request.get(`/album?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};

//获取歌词
export const getLyrics = async (id: string) => {
  try {
    return request.get(`/lyric?id=${id}`);
  } catch (error: any) {
    elMessage(elMessageType.ERROR, error.message);
  }
};
